package com.neusoft.movie.v_movies.activity;

import android.content.Context;
import android.content.SharedPreferences;
import android.provider.ContactsContract;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;

import com.neusoft.movie.v_movies.R;
import com.neusoft.movie.v_movies.common.Constants;
import com.neusoft.movie.v_movies.javabean.ResultBean;
import com.neusoft.movie.v_movies.listener.RetrofitListener;
import com.neusoft.movie.v_movies.model.UsersModel;

public class AddFeedbackActivity extends BaseActivity implements RetrofitListener {

    private Context mContext;
    private String result;
    private int u_id;
    private EditText f_info;
    private Button button_addfb;
    private ImageView left;
    @Override
    void initViews() {
        setLayout(R.layout.activity_add_feedback);
        f_info = (EditText) findViewById(R.id.f_info);
        button_addfb= (Button) findViewById(R.id.button_addfb);

        left=(ImageView) findViewById(R.id.left_button);

    }

    @Override
    void initData() {
        SharedPreferences sharedPreferences=getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        u_id=sharedPreferences.getInt("u_id",0);

    }


    private void addfeedback()
    {
        UsersModel usersModel = new UsersModel();
        usersModel.addfeedback(u_id,
                f_info.getText().toString(),this);
    }

    @Override
    void initEvents() {
        left.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


        button_addfb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addfeedback();
            }
        });

    }

    @Override
    public void onSuccess(Object o, int flag) {
        switch(flag){

            case Constants.ADDDEEDBACK:
                if (((ResultBean)o).getSuccess().equals("1")) {
                    Toast.makeText(AddFeedbackActivity.this, "反馈成功", Toast.LENGTH_LONG).show();
                    finish();
                } else {
                    Toast.makeText(AddFeedbackActivity.this, "反馈失败", Toast.LENGTH_LONG).show();

                }
        }
    }

    @Override
    public void onFailed() {

    }
}